Skip to content

Propagate LaunchInit error code - #41380

Merged
Feng Wang (chemwolf6922) merged 9 commits into
masterfrom
user/chemwolf6922/propagate-launch-init-error
Aug 21, 2026
Merged

Propagate LaunchInit error code#41380
Feng Wang (chemwolf6922) merged 9 commits into
masterfrom
user/chemwolf6922/propagate-launch-init-error

Conversation

@chemwolf6922

@chemwolf6922 Feng Wang (chemwolf6922) commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Summary of the Pull Request

LaunchInit currently try catch _exit(1) all exceptions. This could cause a files system failure being reported to the user as E_UNEXPECTED instead. For example: #13028 and #13237. Where the original EIO at step 3 were collapsed to E_UNEXPECTED.

This PR propagates the error out by removing LaunchInit's own try catch and rely on the caller's try catch logic. And also delays the closure of the original socket fd by setting it to CLOEXEC instead of manually close. So, the caller can still use it in catch.
This PR also adds EIO (5) at step 3 to the treated as disk corruption list.

PR Checklist

Detailed Description of the Pull Request / Additional comments

Validation Steps Performed

Tested by manually injecting an error in LaunchInit:

The distribution failed to start because its virtual disk is corrupted.
Error code: Wsl/Service/CreateInstance/WSL_E_DISK_CORRUPTED

@chemwolf6922
Feng Wang (chemwolf6922) requested a review from a team as a code owner August 19, 2026 03:31
Copilot AI lite review requested due to automatic review settings August 19, 2026 03:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts the Linux-side mini-init launch path so that failures occurring during LaunchInit() are surfaced to the caller’s error-reporting logic (rather than being collapsed to a generic failure), improving the fidelity of error codes reported back to the Windows service during distro startup failures.

Changes:

  • Removed LaunchInit()’s internal try/catch that unconditionally _exit(1)’d, allowing exceptions to propagate to the caller that reports status.
  • Preserved the original launch socket FD for caller-side error reporting by setting FD_CLOEXEC (instead of closing it) after dup2().
  • Added exception logging in ProcessLaunchInitMessage()’s catch block before reporting failure.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/linux/init/main.cpp

@OneBlue Blue (OneBlue) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused by this. #13028 wasn't caused by an IO error, but by a VHD that's missing critical files (like passwd) so this change wouldn't affect that behavior.

Also if we want to cover mount related errors to display the "disk corrupted error", we also need to update this condition so that the LxInitCreateInstanceStepLaunchInit failure step also emits those

@chemwolf6922

Copy link
Copy Markdown
Contributor Author

Hi Blue (@OneBlue) . Before the user tried to fix the file system. The error was LaunchInit fails with EIO because MountInit fails with EIO.
The file missing error was after the file system fix.

    GuestLog,          0,            0,          0,         11,          5,          0,          0, 0x0000000000000000, 0x000017E4, 0x00001C70,                   13,             ,                     ,   {00000000-0000-0000-0000-000000000000},                                         ,   133933240758405979,          0,          0, "[    0.802792] EXT4-fs error (device sdd): ext4_validate_block_bitmap:421: comm LaunchDistro: bg 4185: bad block bitmap checksum ", {759fed4d-944e-4c7d-a4c9-afcfde8482ce}
    GuestLog,          0,            0,          0,         11,          5,          0,          0, 0x0000000000000000, 0x000017E4, 0x00001C70,                   11,             ,                     ,   {00000000-0000-0000-0000-000000000000},                                         ,   133933240758408311,          0,          0, "[    0.803780] Aborting journal on device sdd-8. ", {759fed4d-944e-4c7d-a4c9-afcfde8482ce}
    GuestLog,          0,            0,          0,         11,          5,          0,          0, 0x0000000000000000, 0x000017E4, 0x00001C70,                    3,             ,                     ,   {00000000-0000-0000-0000-000000000000},                                         ,   133933240758441048,          0,          0, "[    0.806941] EXT4-fs (sdd): Remounting filesystem read-only ", {759fed4d-944e-4c7d-a4c9-afcfde8482ce}
    GuestLog,          0,            0,          0,         11,          5,          0,          0, 0x0000000000000000, 0x000017E4, 0x00001C70,                    3,             ,                     ,   {00000000-0000-0000-0000-000000000000},                                         ,   133933240758447325,          0,          0, "[    0.807373] WSL (1 - LaunchDistro) ERROR: CreateTempDirectory:560: mkdtemp(/distro/wslXXXXXX) failed 5 ", {759fed4d-944e-4c7d-a4c9-afcfde8482ce}
    GuestLog,          0,            0,          0,         11,          5,          0,          0, 0x0000000000000000, 0x000017E4, 0x00001C70,                    3,             ,                     ,   {00000000-0000-0000-0000-000000000000},                                         ,   133933240758452044,          0,          0, "[    0.807982] WSL (1 - LaunchDistro) WARNING: Detected read-only or full filesystem. Adding a tmpfs overlay ", {759fed4d-944e-4c7d-a4c9-afcfde8482ce}
Request_Tstatfs,          0,            0,          0,         11,          5,          0,          0, 0x0000000000000000, 0x0000317C, 0x00001DB4,                   11,             ,                     ,   {00000000-0000-0000-0000-000000000000},                                         ,   133933240758457071,          0,          0,      0,        1
StorVspVsmbRelativeCreate,          1,            0,          0,         11,          4,          1,          0, 0x0000000000000100, 0x0000317C, 0x00001DB4,                   11,             ,                     ,   {f71eb5cb-d391-000b-7f43-1ff791d3db01},                                         ,   133933240758457177,          0,          0, 0xFFFF9D01EA1C3880, ""
StorvspVsmbDownlevelCreate,          1,            0,          0,         11,          4,          1,          0, 0x0000000000000100, 0x0000317C, 0x00001DB4,                   11,             ,                     ,   {f71eb5cb-d391-000b-8043-1ff791d3db01},   {f71eb5cb-d391-000b-7f43-1ff791d3db01},   133933240758457197,          0,          0, 0xFFFF9D01EA1C3880, ""
StorvspVsmbDownlevelCreate,          2,            0,          0,         11,          4,          2,          0, 0x0000000000000100, 0x0000317C, 0x00001DB4,                   11,             ,                     ,   {f71eb5cb-d391-000b-8043-1ff791d3db01},   {f71eb5cb-d391-000b-7f43-1ff791d3db01},   133933240758457631,          0,          0, 0xFFFF9D01EA1C3880, STATUS_SUCCESS
Microsoft-Windows-Hyper-V-StorageVSP ,          0,         1010,          0,         17,          4,          0,          0, 0x0000000000000004, 0x0000317C, 0x00001DB4,                   11,             ,                     ,   {f71eb5cb-d391-000b-7f43-1ff791d3db01},                                         ,   133933240758457674,          0,          0, "VspVsmbCommonRelativeCreate",     1363, "VspVsmbCommonRelativeCreate: Create  DA 0x100080 FA 0x2000080 SA 0x7 CD 0x1 CO 0x200000 eaBuffer 0000000000000000 eaLength 0 Imp? N bu? N status 0x00000000 info 0x1"
StorVspVsmbRelativeCreate,          2,            0,          0,         11,          4,          2,          0, 0x0000000000000100, 0x0000317C, 0x00001DB4,                   11,             ,                     ,   {f71eb5cb-d391-000b-7f43-1ff791d3db01},                                         ,   133933240758457781,          0,          0, 0xFFFF9D01EA1C3880, STATUS_SUCCESS
Reply_Rstatfs,          0,            0,          0,         11,          5,          0,          0, 0x0000000000000000, 0x0000317C, 0x00001DB4,                   11,             ,                     ,   {00000000-0000-0000-0000-000000000000},                                         ,   133933240758458012,          0,          0,      0, 16914839,     4096,        243995647,        177407225,        177407225,              999,          1000000,                1,      255
Request_Tstatfs,          0,            0,          0,         11,          5,          0,          0, 0x0000000000000000, 0x0000317C, 0x00001DB4,                   11,             ,                     ,   {00000000-0000-0000-0000-000000000000},                                         ,   133933240758459512,          0,          0,      0,        1
StorVspVsmbRelativeCreate,          1,            0,          0,         11,          4,          1,          0, 0x0000000000000100, 0x0000317C, 0x00001DB4,                   11,             ,                     ,   {f71eb5cb-d391-000b-8143-1ff791d3db01},                                         ,   133933240758459575,          0,          0, 0xFFFF9D01EA1C3EB0, ""
StorvspVsmbDownlevelCreate,          1,            0,          0,         11,          4,          1,          0, 0x0000000000000100, 0x0000317C, 0x00001DB4,                   11,             ,                     ,   {f71eb5cb-d391-000b-8243-1ff791d3db01},   {f71eb5cb-d391-000b-8143-1ff791d3db01},   133933240758459584,          0,          0, 0xFFFF9D01EA1C3EB0, ""
StorvspVsmbDownlevelCreate,          2,            0,          0,         11,          4,          2,          0, 0x0000000000000100, 0x0000317C, 0x00001DB4,                   11,             ,                     ,   {f71eb5cb-d391-000b-8243-1ff791d3db01},   {f71eb5cb-d391-000b-8143-1ff791d3db01},   133933240758459750,          0,          0, 0xFFFF9D01EA1C3EB0, STATUS_SUCCESS
Microsoft-Windows-Hyper-V-StorageVSP ,          0,         1010,          0,         17,          4,          0,          0, 0x0000000000000004, 0x0000317C, 0x00001DB4,                   11,             ,                     ,   {f71eb5cb-d391-000b-8143-1ff791d3db01},                                         ,   133933240758459773,          0,          0, "VspVsmbCommonRelativeCreate",     1363, "VspVsmbCommonRelativeCreate: Create  DA 0x100080 FA 0x2000080 SA 0x7 CD 0x1 CO 0x200000 eaBuffer 0000000000000000 eaLength 0 Imp? N bu? N status 0x00000000 info 0x1"
StorVspVsmbRelativeCreate,          2,            0,          0,         11,          4,          2,          0, 0x0000000000000100, 0x0000317C, 0x00001DB4,                   11,             ,                     ,   {f71eb5cb-d391-000b-8143-1ff791d3db01},                                         ,   133933240758459823,          0,          0, 0xFFFF9D01EA1C3EB0, STATUS_SUCCESS
Reply_Rstatfs,          0,            0,          0,         11,          5,          0,          0, 0x0000000000000000, 0x0000317C, 0x00001DB4,                   11,             ,                     ,   {00000000-0000-0000-0000-000000000000},                                         ,   133933240758460084,          0,          0,      0, 16914839,     4096,        243995647,        177407225,        177407225,              999,          1000000,                1,      255
    GuestLog,          0,            0,          0,         11,          5,          0,          0, 0x0000000000000000, 0x000017E4, 0x00001C70,                   11,             ,                     ,   {00000000-0000-0000-0000-000000000000},                                         ,   133933240758468736,          0,          0, "[    0.809827] overlayfs: failed to get metacopy (-5) ", {759fed4d-944e-4c7d-a4c9-afcfde8482ce}
    GuestLog,          0,            0,          0,         11,          5,          0,          0, 0x0000000000000000, 0x000017E4, 0x00001C70,                   11,             ,                     ,   {00000000-0000-0000-0000-000000000000},                                         ,   133933240758472323,          0,          0, "[    0.810095] WSL (1) ERROR: I/O error @main.cpp:2395 (MountInit) ", {759fed4d-944e-4c7d-a4c9-afcfde8482ce}
    GuestLog,          0,            0,          0,         11,          5,          0,          0, 0x0000000000000000, 0x000017E4, 0x00001C70,                   11,             ,                     ,   {00000000-0000-0000-0000-000000000000},                                         ,   133933240758475600,          0,          0, "[    0.810437] WSL (1) ERROR: I/O error @main.cpp:1853 (LaunchInit) ", {759fed4d-944e-4c7d-a4c9-afcfde8482ce}
       Error,          0,            0,          0,         11,          2,          0,          0, 0x0000000000000000, 0x000017E4, 0x00002E64,                   15,             ,                     ,   {00000000-0000-0000-0000-000000000000},                                         ,   133933240758477600,         15,         15, "C:\__w\1\s\src\shared\inc\SocketChannel.h",      251,        0,        3,    11876, 0x8000FFFF, "Expected message LxMiniInitMessageCreateInstanceResult, but socket WslCorePort was closed", "", ""
CreateInstanceEnd,          0,            0,          0,         11,          5,          0,          0, 0x0000000000000000, 0x000017E4, 0x00002E64,                   15,             ,                     ,   {00000000-0000-0000-0000-000000000000},                                         ,   133933240758478565,         15,         15, "2.5.7.0",         16777216, "Ubuntu",        2, {2cdfb0e5-c0c1-448b-8c5a-28c3205b3020}, 0, -2147418113
  VerboseLog,          0,            0,          0,         11,          5,          0,          0, 0x0000000000000000, 0x000017E4, 0x00002E64,                   15,             ,                     ,   {00000000-0000-0000-0000-000000000000},                                         ,   133933240758480134,         15,         15, "C:\__w\1\s\src\windows\service\exe\LxssUserSession.cpp",      759,        4,    11876, 0x8000FFFF, "C:\__w\1\s\src\shared\inc\SocketChannel.h(251)\wslservice.exe!00007FF639F4A1A3: (caller: 00007FF639F93656) Exception(3) tid(2e64) 8000FFFF Katastrof�ln� selh�n�      Msg:[Expected message LxMiniInitMessageCreateInstanceResult, but socket WslCorePort was closed]  ", "", ""
    GuestLog,          0,            0,          0,         11,          5,          0,          0, 0x0000000000000000, 0x000017E4, 0x00001C70,                    3,             ,                     ,   {00000000-0000-0000-0000-000000000000},                                         ,   133933240758482414,          0,          0, "[    0.810969] WSL (1 - init-distro) ERROR: InitEntryUtilityVm:2572: Init has exited. Terminating distribution ", {759fed4d-944e-4c7d-a4c9-afcfde8482ce}
LxssException,          0,            0,          0,         11,          2,          0,          0, 0x0000000000000000, 0x00003178, 0x0000155C,                   15,             ,                     ,   {00000000-0000-0000-0000-000000000000},                                         ,   133933240758482476,         15,          0, "C:\__w\1\s\src\windows\common\WslClient.cpp", "",      701,        0, 0x8000FFFF, "", ""
    GuestLog,          0,            0,          0,         11,          5,          0,          0, 0x0000000000000000, 0x000017E4, 0x00001C70,                   13,             ,                     ,   {00000000-0000-0000-0000-000000000000},                                         ,   133933240758492901,          0,          0, "[    0.812078] EXT4-fs (sdd): unmounting filesystem e1bd6dbd-cb4b-4bdc-b3b9-35a819be0d91. ", {759fed4d-944e-4c7d-a4c9-afcfde8482ce}

@chemwolf6922

Copy link
Copy Markdown
Contributor Author

Also if we want to cover mount related errors to display the "disk corrupted error", we also need to update this condition so that the LxInitCreateInstanceStepLaunchInit failure step also emits those

I was a bit hesitant to treat all EIO in this step as disk corruption. But I guess it's ok.

Copilot AI review requested due to automatic review settings August 20, 2026 03:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Suppressed comments (2)

src/linux/init/main.cpp:1502

  • SetCloseOnExec() is documented/implemented to return 0 on success and -1 on failure (main.cpp:3556-3559). Most call sites in this file compare the return value against < 0 (e.g., main.cpp:1048, 1053). Using THROW_LAST_ERROR_IF(SetCloseOnExec(...)) relies on implicit int-to-bool conversion and is inconsistent with the established pattern.
        THROW_LAST_ERROR_IF(SetCloseOnExec(SocketFd, true));

src/windows/service/exe/WslCoreInstance.cpp:71

  • Use the EIO errno constant instead of the magic value 5 for readability and to avoid baking in a numeric errno mapping.
        if (((result.Result == EINVAL || result.Result == 74 || result.Result == 117) && result.FailureStep == LxInitCreateInstanceStepMountDisk) ||
            (result.Result == 5 && result.FailureStep == LxInitCreateInstanceStepLaunchInit))

@chemwolf6922

Feng Wang (chemwolf6922) commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

Note: used 5 instead of EIO. As the EIO in this file is the Windows EIO. Which happens to be the same as Linux.

@chemwolf6922
Feng Wang (chemwolf6922) merged commit 84ec12b into master Aug 21, 2026
11 checks passed
@chemwolf6922
Feng Wang (chemwolf6922) deleted the user/chemwolf6922/propagate-launch-init-error branch August 21, 2026 02:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants